<template>
  <div class="app-container">
    {{$t('setting.Collected_point_setting')}}
    <div class="filter-container" style="overflow:hidden">
      {{$t('setting.Consume_$1_can_get')}}：<el-input-number v-model="coin" :min="0"  label="描述文字"></el-input-number> {{$t('setting.Collected_point')}}
    </div>
    <div class="filter-container" style="overflow:hidden">
      {{$t('setting.1_point_deducts')}}&nbsp;&nbsp;&nbsp;： <el-input-number v-model="price" :precision="1" :min="0"  label="描述文字"></el-input-number>
      {{$t('setting.AUD')}}
    </div>
    <el-button @click="confirm" type="primary" style="margin-top:50px;margin-left:10px;width:100px">{{$t('common.Save')}}</el-button>
  </div>
</template>

<script>
import { getSystemParamter , updateSystemParamter } from '@/api/system'
export default {
  name: 'setting_point',
  data(){
    return{
      coin:'',
      price:'',
    }
  },
  methods:{
    // 获取积分
    async getCoin(){
      const { data } = await getSystemParamter({
        key:'SYS00005',
      })
      this.coin = data.systemValue
    },
    // 获取金额
    async getPrice(){
      const { data } = await getSystemParamter({
        key:'SYS00006',
      })
        this.price = data.systemValue
    },
    async postCoin(){
      const{ data } = await updateSystemParamter({
          key:'SYS00005',
          value:this.coin
        })  
    },
    async postPrice(){
        const{ data } = await updateSystemParamter({
          key:'SYS00006',
          value:this.price
        })
    },
    async confirm(){
        if(!this.price || !this.coin)
        {
          this.$message({
              type:'error',
              message:'内容不能为空'
          });
          return
        }
        await Promise.all([this.postCoin(), this.postPrice()])  
        this.$message({
          type: 'success',
          message: `修改成功!`
        });
        this.getCoin()
        this.getPrice()
    }
  },
  created(){
    this.getCoin()
    this.getPrice()
  },
}
</script>

<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0;
}
</style>
